package com.wcity.manage.common.utils;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 银联支付工具类
 *
 * @author dy
 */
public class UnionPayUtil {



    /**
     * 将所有参数值按升序排序
     *
     * @param params
     * @return
     */
    public static String sortParamsToSign( Map<String, String> params ) {

        List<String> valList = Arrays.asList( params.keySet().toArray( new String[params.size()] ) );
        Collections.sort( valList );
        StringBuilder sb = new StringBuilder();
        for ( String k : valList ) {
            if ( k.equals( "sign" ) ) {
                continue;
            }
            sb.append (k ).append( "=" ).append( params.get(k) ).append( "&" );
        }
        if ( params.size() >= 1 )
            sb.delete( sb.length() - 1, sb.length() ); // 去掉最后一个字符
        String signStr = sb.toString();
        return signStr;
    }
}
